<?php
//PDO使用示例

//数据库参数
$db_dns = "mysql:host=127.0.0.1;dbname=gamebox;";
$db_user = "gamebox_user";
$db_password = "123456a";


//连接数据库
try{
	$dbh = new PDO($db_dns,$db_user,$db_password,array(PDO::MYSQL_ATTR_INIT_COMMAND=>'set names utf8'));
}catch(PDOException $e){
	echo $e->getMessage();
	exit();
}

//查询数据
$sql = "SELECT * FROM gamebox_tag_type WHERE type_id>=:id";
$stmt = $dbh->prepare($sql);
$stmt->bindParam(":id",$id);
$stmt->execute();
$vo = $stmt->fetchAll();
//$vo = $stmt->fetch();
//$vo = $stmt->fetchColumn();
var_dump($vo);
//echo $vo[0]['type_id'];

echo "<br /><br /><br />";


//更新数据
$sql2 = "update gamebox_tag_type set type_remarks=:type_remarks  WHERE type_id>=:id";
$stmt2 = $dbh->prepare($sql2);
$stmt2->bindParam(":id",$id);
$stmt2->bindParam(":type_remarks",$type_remarks);
$stmt2->execute();
//$stmt2->rowCount() 可以获得受影响的行数
echo "更新了".$stmt2->rowCount()."行";


$sql2 = "insert into gamebox_tag_type set type_name=:type_name,type_remarks=:type_remarks,type_isDeleted=:type_isDeleted";
$stmt2 = $dbh->prepare($sql2);

$type_name = "测试新增加";
$type_remarks = "测试备注啊啊啊";
$type_isDeleted = false;

$stmt2->bindParam(":type_name",$type_name);
$stmt2->bindParam(":type_remarks",$type_remarks);
$stmt2->bindParam(":type_isDeleted",$type_isDeleted);
$stmt2->execute();
//$dbh->lastInsertId()获得刚刚新增加的自动ID
echo "新增加的ID是".$dbh->lastInsertId();

?>